<?php 

/*====================================================
 Author: RooTM
------------------------------------------------------
 Web-site: http://weboss.net/
=====================================================*/

if( ! defined( 'DATALIFEENGINE' ) ) {
	die( "Hacking attempt!" );
}

if($run_in != 'AJAX') $news_id = $_GET['newsid'];

if($place != 'news') $place = 'comments';

if($place == 'news') $file_name = ENGINE_DIR . '/modules/iLike/base/news-'.$news_id.'.data';
if($place == 'comments') $file_name = ENGINE_DIR . '/modules/iLike/base/nid-'.$news_id.'_cid-'.$comment_id.'.data';

include ENGINE_DIR . '/modules/iLike/language.lng';

$action_hash = md5( md5($place) . md5($news_id) . md5($comment_id) . md5(DBPASS) . md5($member_id['name']) );

$like_data = @file_get_contents( $file_name );

$user = explode( "\n\n" , $like_data );

$sum_like = count($user)-1;

if($run_in != 'AJAX') echo "<link media=\"screen\" href=\"{$config['http_home_url']}engine/modules/iLike/style.css\" type=\"text/css\" rel=\"stylesheet\" />";

if($run_in != 'AJAX') echo "<script type=\"text/javascript\" src=\"{$config['http_home_url']}engine/modules/iLike/action.js\"></script>";

if(!preg_match( "<!-- UserID: ".$member_id['user_id']." -->" , $like_data ) ){

if($sum_like == 1) $iLike = $user[0].$iLike_lang[1].'.';

if($sum_like == 2) $iLike = $user[0].$iLike_lang[2].$user[1].$iLike_lang[1].'.';

if($sum_like == 3) $iLike = $user[0].', '.$user[1].$iLike_lang[2].$user[2].$iLike_lang[1].'.';

if($sum_like > 3){
if(($sum_like - 3) == 1) $other_title = $iLike_lang[5]; else $other_title =  ($sum_like - 3).$iLike_lang[6];
$other =  "<a href=\"#\" onclick=\"iLikeOther( '{$news_id}', '{$comment_id}', '{$place}' ); return false;\" >".$other_title."</a>".$iLike_lang[1];
$iLike = $user[0].', '.$user[1].', '.$user[2].$iLike_lang[2].$other.'.';
}

$button = "<input class=\"bbcodes\" style=\"font-size: 9px; float: right;\" title=\"{$iLike_lang[8]}\" onclick=\"iLikeAction( 'plus', '{$news_id}', '{$comment_id}', '{$action_hash}', '{$place}' ); return false;\" type=\"button\" value=\"{$iLike_lang[8]}\" /><br />";

}elseif(preg_match( "<!-- UserID: ".$member_id['user_id']." -->" , $like_data ) ){

preg_match( '/<!-- UserID: '.$member_id['user_id'].' -->(.*?)\n\n/is' , $like_data , $me );

$user = explode( "\n\n" , str_replace ( "<!-- UserID: ".$member_id['user_id']." -->".$me[1]."\n\n" , '' ,  $like_data ) );

if($sum_like == 1) $iLike = $iLike_lang[3];

if($sum_like == 2) $iLike = $iLike_lang[4].$iLike_lang[2].$user[0].'.';

if($sum_like == 3) $iLike = $iLike_lang[4].', '.$user[0].' è '.$user[1].'.';

if($sum_like > 3){
if(($sum_like - 3) == 1) $other_title = $iLike_lang[7]; else $other_title =  ($sum_like - 3).$iLike_lang[6];
$other =  "<a href=\"#\" onclick=\"iLikeOther( '{$news_id}', '{$comment_id}', '{$place}' ); return false;\" >".$other_title."</a>";
$iLike = $iLike_lang[4].', '.$user[0].', '.$user[1].$iLike_lang[2].$other.'.';
}

$button = "<input class=\"bbcodes\" style=\"font-size: 9px; float: right;\" title=\"{$iLike_lang[9]}\" onclick=\"iLikeAction( 'minus', '{$news_id}', '{$comment_id}', '{$action_hash}', '{$place}' ); return false;\" type=\"button\" value=\"{$iLike_lang[9]}\" /><br />";

}

if($run_in != 'AJAX') if($place == 'news') echo '<div id="likes-'.$place.$news_id.'">'; else echo '<div id="likes-'.$place.$comment_id.'">';

if( $is_logged ) echo $button;

if(trim($like_data) != ''){
echo '<div class="likesSummary secondaryContent"><span class="LikeText">';
echo $iLike;
echo '</span></div>';
}

if($run_in != 'AJAX') echo '</div>';

?>